const request = {}
const headers = {}




request.imgUrl='https://pp.scjywkj.com'
var urlConfig = 'https://pp.scjywkj.com'
request.api = 'https://pp.scjywkj.com'
//请求
request.globalRequest = (...arr) => {
	return uni.request({
		url: urlConfig + arr[0],
		method: arr[1] || "GET",
		data: arr[2] ? arr[2] : {},
		withCredentials: false,
		header: arr[3] || {
			Authorization: 'Bearer '+uni.getStorageSync("token")
		}
	}).then(res => {
		console.log(res)
		if (res.data.code == 40401 ) {
			uni.reLaunch({
				url: '/pages/login/login'
			});
			return
		}
		if(res.data.code!=10000){
				uni.showToast({
					title: res.data.message,
					icon: "none"
				})
				return
		}
		
		// 200状态处理
		// console.log(res)
		if (res.statusCode == 200) {
			return res.data
		} else {
			throw res.data
		}
	}).catch(parmas => {
		console.log(parmas)
		switch (parmas.code) {
			case 401:
				uni.clearStorageSync()
				break
			default:
				return Promise.reject()
		}
	})
}

export default request
